package com.accountant.travelaccountant;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ResultScreen2_Listview_Adapter extends BaseAdapter {
	ResultScreen2 resultScreen2;
	ArrayList<String> messages;
	Context context;
	Views views;

	public ResultScreen2_Listview_Adapter(ResultScreen2 resultScreen2,
			ArrayList<String> messages, Context context) {
		this.resultScreen2 = resultScreen2;
		this.messages = messages;
		this.context = context;
	}

	private class Views {
		TextView textView;
	}

	@Override
	public int getCount() {
		return messages.size();
	}

	@Override
	public Object getItem(int arg0) {
		return messages.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		/* Creating an inflater */
		LayoutInflater layoutInflater = resultScreen2.getLayoutInflater();
		if (convertView == null) {
			/*
			 * Create an object so that it can the references of all the
			 * controls
			 */
			views = new Views();
			/*
			 * Assigning the view of all the textviews which you want into every
			 * listview
			 */
			convertView = layoutInflater.inflate(
					R.layout.resultscreen2_listview_layout, null);
			/* Assigning the ids to store references */
			views.textView = (TextView) convertView
					.findViewById(R.id.textViewforResultscreen2_listview_layout);
			/* Assigning the object to the view */
			convertView.setTag(views);
			convertView.setTag(R.id.textViewforResultscreen2_listview_layout, views.textView);
		} else {
			/*
			 * Get view is called every time setAdapter is calling itself to add
			 * a view
			 */
			views = (Views) convertView.getTag();
		}
		/*
		 * Arraylists of hashmaps come and then every time a new hashmap is
		 * assigned
		 */
		views.textView.setText(messages.get(position));
		convertView= HelperClassForActivities.addColourToListView(position,convertView,resultScreen2);
		
		return convertView;
	}
	
	

}
